(function() {
	sharpRegistry.panes['default.folder.footer'] = new Class({
		initialize: function(footerId) {
			var footer = new Element('div', { 'id': footerId });
			
			footer.grab(new Element('input', {
				'type': 'button',
				'value': 'Reporting',
				'events': {
					'click': function() {
						target = document.id('content');
						target.empty();
						
						var header = new Element('div', { 'id': 'header'}),
							footer = new Element('div', {'id': 'footer'});
							
						header.grab(new Element('h2', {'text': 'Reporting'}));
						footer.grab(new Element('input', {
							'type': 'button',
							'value': 'Cancel',
							'events': {
								'click': function() {
									document.id('content').empty();
								}
							}
						}));
						target.grab(header);
						target.grab(new Element('div', {'id': 'pane' }).grab(new ReportPanel()));
						target.grab(footer);
						resizeContent();
					}
				}
			}));
			footer.grab(new Element('input', {
									'type': 'button',
									'value': ' + Add',
									'id': 'add-item-button',
									'styles': { 'float': 'left' },
									'events': {
										'click': function () {
											mc.report(sharpbar.applicationUrl, 'resource-providers', function (xmlReport) {
												var providers = new Array(xmlReport.getElementsByTagName('mc:provider')).flatten();
												var newItemWidget = new sharpRegistry.widgets['modal'](sharpbar.applicationUrl, providers, new Hash({
													'containerId': 'browse-folder-popover',
													'windowTitleBarId': 'browse-window-title',
													'paneConfig' : new Hash({}),
													'getPaneOverride': function (url, providers) {
														var widget = new Element('div'), 
															selectList = new Element('select', { 'id': 'select-provider' }),
															opt,
															options = providers.map(function(provider) {
																opt = new Element('option', {
																	'value': provider.getAttribute('id'),
																	'text': provider.getAttribute('name')
															});
															
															return opt;
														});
	
														selectList.adopt(options);
														widget.grab(new Element('label', { 'for': 'itemName', 'text': 'Name: '}));
														widget.grab(new Element('input', { 'id': 'itemName' }));
														widget.grab(selectList);
														widget.grab(new Element('input', { 
															'type': 'button',
															'value': 'Create',
															'events': {
																'click': function () {
																	var name = document.id('itemName').value,
																		providerId = document.id('select-provider').value,
																		itemUrl = sharpRegistry.activePanes.folder.folderUrl + '/' + name; //url + '/' + name;
																	if (!name) {
																		alert("Please enter an item name.");
																		return;
																	}
																	mc.put(itemUrl, '', function (itemUrl, xml, location) {
																		mc.proppatch(location, function (responseXml) {
																			var hrefNode = responseXml.getElementsByTagName("D:href")[0],
																				forwardToHref = hrefNode ? hrefNode.textContent ? hrefNode.textContent : hrefNode.text : sharpbar.applicationUrl,
																				itemInfoElement;
																			if (sharpRegistry.activePanes.item) {
																				itemInfoElement = document.id(sharpRegistry.activePanes.item.displayElementId);
																			}
																			else {
																				itemInfoElement = document.id('content');
																			}
																			if (itemInfoElement)
																				itemInfoElement.empty();
																			
																			//document.id('browse-folder-popover').destroy(); // TODO: Use handle to widget to hide it...
																			//sharpbar.browser.openByUrl(itemUrl + '?ver=1');
																			window.location.href = forwardToHref;
																		}, new Hash({
																				'mc:resourceprovider': [['innerText', providerId]],
																				'mc:mimetype': [['innerText', 'text/html']],
																				'mc:published': [['innerText', 'true']]
																			}));
																	});
																}
															}
														}));
														this.navigationPane = widget;
													}
												}));
												if (newItemWidget) {
													newItemWidget.show();
													window.scrollTo(0,0);
												}
											});
										}
									}
								}));
/*
			var searchBlock = new Element('div', {
				'styles': {
					'float': 'left',
					'margin-left': '10px'
				}
			});
			searchBlock.grab(new Element('input', {
				'type': 'button',
				'value': 'Search',
				'events': {
					'click': function() {
						mc.search(sharpbar.applicationUrl, document.id('inventorySearch').value, function(xml) {
							alert(xml);
						});
					}
				},
				'styles': {
					'margin-top': '-1px'
				}
			}));
			searchBlock.grab(new Element('input', {
				'type': 'text',
				'id': 'inventorySearch',
				'styles': {
					'margin-right': '0px'
				}
			}));
			footer.grab(searchBlock);
*/
			footer.grab(new Element('div', { 
				'styles': { 
					'clear': 'both',
					'font-size': '.75em',
					'margin-left': '12px' 
				}
			}));
			return footer;
		}
	});
})();
